package com.vlin.scene.actuator.defaut;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONObject;

import com.vlin.entity.scene.Command;
import com.vlin.scene.actuator.CommandProducer;
import com.vlin.scene.actuator.ListCommandProducer;

public class DefaultListCommandProducer implements ListCommandProducer {

	private List<CommandProducer> list = new ArrayList<>();
	
	@Override
	public Command produce(JSONObject command) {
		for(CommandProducer producer : list) {
			if(producer.support(command)) {
				return producer.produce(command);
			}
		}
		return null;
	}

	@Override
	public boolean support(JSONObject command) {
		for(CommandProducer producer : list) {
			if(producer.support(command)) {
				return true;
			}
		}
		return false;
	}

	@Override
	public void addCommandProducer(CommandProducer commandProducer) {
		if(commandProducer != null) {
			list.add(commandProducer);
		}
		
	}

	

}
